//
//  WYDoneMessageController.m
//  Boss
//
//  Created by admin on 2018/6/26.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYDoneMessageController.h"
#import "WYDataPicker.h"
#import "CZHAddressPickerView.h"
#import "AddressPickerHeader.h"



@interface WYDoneMessageController ()

@property (strong, nonatomic) IBOutlet UIButton *maleButton;
@property (strong, nonatomic) IBOutlet UIButton *femaleButton;
@property (strong, nonatomic) IBOutlet UILabel *ageLabel;
@property (strong, nonatomic) IBOutlet UILabel *addressLabel;
@property (nonatomic,strong)  WYDataPicker *datePicker;

@property (nonatomic, copy) NSString *province;

@property (nonatomic, copy) NSString *city;

@property (nonatomic, copy) NSString *area;

@property (nonatomic,strong)NSString *date;

@end

@implementation WYDoneMessageController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor whiteColor];
    [self wr_setNavBarBackgroundAlpha:0];
    [self setupUI];
}
-(void)setupUI
{
    [self.maleButton setCornerRadius:8.f];
    [self.maleButton setBorderWithWidth:kLineHeight andColor:kColorMainColor];
    [self.maleButton setTitleColor:kColorMainColor forState:(UIControlStateSelected)];
//    [self.maleButton setTitleColor:kColor999999 forState:(UIControlStateNormal)];
  //  [self.maleButton setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    
    
    [self.femaleButton setCornerRadius:8.f];

    [self.femaleButton setBorderWithWidth:kLineHeight andColor:kColor999999];
    //[self.femaleButton setTitleColor:kColorMainColor forState:(UIControlStateSelected)];
//    [self.femaleButton setTitleColor:kColor999999 forState:(UIControlStateNormal)];
//
    self.maleButton.selected = YES;
    
    WEAKSELF
    WYDataPicker *datePicker = [[WYDataPicker alloc]initWithFrame:CGRectMake(0, kScreenHeight-214, kScreenWidth, 214)];
    datePicker.type = @"11";
    datePicker.complete = ^(NSString *date) {
        weakSelf.ageLabel.text =[NSString stringWithFormat:@"%.0f",[weakSelf calculateAge:date]];
        weakSelf.date = date;
    };
    [self.view addSubview:datePicker];
    datePicker.hidden = YES;
    self.datePicker = datePicker;
    
}
- (double )calculateAge:(NSString *)str {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd";
    NSDate *birthDay = [dateFormatter dateFromString:str];
    //获取时间戳，时间戳是负数
    NSTimeInterval time = [birthDay timeIntervalSinceNow];
    double year = floor(ABS(time)/(3600.0 * 24 * 365)); //3600秒 * 24小时*365天
    return year;
}
- (IBAction)addressAction:(id)sender {
    WEAKSELF
    [CZHAddressPickerView areaPickerViewWithProvince:self.province city:self.city area:self.area areaBlock:^(NSString *province, NSString *city, NSString *area) {
       // CZHStrongS elf(self);
        weakSelf.province = province;
        weakSelf.city = city;
        weakSelf.area = area;
        
        weakSelf.addressLabel.text = [NSString stringWithFormat:@"%@ %@ %@",province,city,area];
    }];
    
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)DoneAction:(id)sender {
    
    WEAKSELF
   [WYHttpServer donePersonalMessageWithSex:self.maleButton.selected?@"1":@"0" WithBirthday:self.date WithProvince:self.province WithCity:self.city WithPrefecture:self.area SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
       if (success) {
           [weakSelf dismissViewControllerAnimated:YES completion:nil];
       }
   }];
   // [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)maleAction:(id)sender {
    self.maleButton.selected = YES;
    self.femaleButton.selected = NO;
    [self.maleButton setCornerRadius:8.f];
    [self.maleButton setBorderWithWidth:kLineHeight andColor:kColorMainColor];
    [self.maleButton setTitleColor:kColorMainColor forState:(UIControlStateNormal)];
    [self.maleButton setTitleColor:kColor999999 forState:(UIControlStateNormal)];
    
    
    [self.femaleButton setCornerRadius:8.f];
    [self.femaleButton setBorderWithWidth:kLineHeight andColor:kColor999999];
    [self.femaleButton setTitleColor:kColorMainColor forState:(UIControlStateSelected)];
    [self.femaleButton setTitleColor:kColor999999 forState:(UIControlStateNormal)];
    
    
    
}
- (IBAction)femaleAction:(id)sender {
    self.maleButton.selected = NO;
    self.femaleButton.selected = YES;
    [self.maleButton setCornerRadius:8.f];
    [self.maleButton setBorderWithWidth:kLineHeight andColor:kColor999999];
    [self.maleButton setTitleColor:kColorMainColor forState:(UIControlStateSelected)];
    [self.maleButton setTitleColor:kColor999999 forState:(UIControlStateNormal)];

    
    
    [self.femaleButton setCornerRadius:8.f];
    [self.femaleButton setBorderWithWidth:kLineHeight andColor:kColorMainColor];
    [self.femaleButton setTitleColor:kColorMainColor forState:(UIControlStateSelected)];
    [self.femaleButton setTitleColor:kColorMainColor forState:(UIControlStateNormal)];
    
    
    
}
- (IBAction)ageAction:(id)sender {
    self.datePicker.hidden  =  NO;
    //[self.view addSubview:self.maskView];
    
}

- (IBAction)jumpAction:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
    
    
}



@end
